<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 1000px;
            height: 200px;
            background-color: pink;
            margin: 100px auto;
            text-align: center;
            font-size: 50px;
            line-height: 200px;
            font-weight: 700;
        }

        .box1 {
            position: absolute;
            right: 20px;
            top: 10px;
            width: 20px;
            height: 20px;
            background-color: skyblue;
            text-align: center;
            line-height: 20px;
            font-size: 16px;
            cursor: pointer;
        }
    </style>
</head>

<body>
<div class="box" id="box">
    我是广告
    <div class="box1" id="box1">X</div>
</div>
<script>
    //获取事件源 你要去点击的按钮
    /*var box1 = document.querySelector("#box1");
    var box = document.querySelector("#box");
    //进行事件的监听 addEventListener监听器
    box1.addEventListener('click', function () {
        //直接让父盒子不显示
        box.style.display = 'none';
    })*/

    var box1 = document.getElementById("box1");
    var box = document.getElementById("box");
    box1.onclick = function () {
        box.style.display = 'none';
    }


</script>
</body>

</html>